package com.itheima.consumer.config;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Directconfiguration {


    //定义一个fanout交换机(两种方式)
    @Bean
    public DirectExchange directExchange() {
    return ExchangeBuilder.directExchange("hamll.direct").build();  //用ExchangeBuilder这个接口调用实现类build出来
    }

    //创建队列
    @Bean
    public Queue directQueue1() {
        return QueueBuilder.durable("direct.queue1").build();// build出来 durable将会持久化到磁盘,让消息持久化
    }

    //绑定队列和交换机关系 with:routingKey
    //这里申明多个routingKey需要多次创建bean去绑定 以下两个方法一个绑定red 一个绑定blue,但是都是对同一个队列和交换机之间的绑定
    @Bean
    public Binding directQueue1BindingRed() {
        return BindingBuilder.bind(directQueue1()).to(directExchange()).with("red");
    }

    //绑定队列和交换机关系
    @Bean
    public Binding directQueue1BindingBlue() {
        return BindingBuilder.bind(directQueue1()).to(directExchange()).with("blue");
    }

    //创建队列
    @Bean
    public Queue directQueue2() {
        return QueueBuilder.durable("direct.queue2").build();// build出来 durable将会持久化到磁盘,让消息持久化
    }

    //绑定队列和交换机关系
    @Bean
    public Binding directQueue2BindingRed() {
    return BindingBuilder.bind(directQueue2()).to(directExchange()).with("red");
    }

    //绑定队列和交换机关系
    @Bean
    public Binding directQueue2BindingYellow() {
    return BindingBuilder.bind(directQueue2()).to(directExchange()).with("yellow");
    }



}
